<template>
    <div class='disinblock user-box posi-rel ml20' v-show='userid'>
      <span class="disinblock user-name mr20 fs12">{{ profile.nickname }}</span>
      <div class='user-img cursor-pointer posi-rel' @mouseenter="toogleUserList(true)"
        @mouseleave="toogleUserList(false)">
        <img class='disinblock' :src=avatar alt="">
        <div class="user-list-box" v-show='isUserListShow'>
          <!-- 小三角 -->
          <div class='user-list-h'></div>
          <!-- 用户信息 -->
          <div class='user-list'>
            <ul>
              <li @click="routerToUser(userid)">
                <a href="javascript:;">
                    <i class='icon-host'></i>
                    <span>我的主页</span>
                </a>
              </li>
              <li>
                <a href="javascript:;">
                    <i class='icon-msg'></i>
                    <span>我的消息</span>
                </a>
              </li>
              <li>
                <a href="javascript:;">
                    <i class='icon-lvl'></i>
                    <span>我的等级</span>
                </a>
              </li>
              <li>
                <a href="javascript:;">
                    <i class='icon-vip'></i>
                    <span>VIP会员</span>
                </a>
              </li>
              <li>
                <a href="javascript:;">
                    <i class='icon-setting'></i>
                    <span>个人设置</span>
                </a>
              </li>
              <li>
                <a href="javascript:;">
                    <i class='icon-real-name'></i>
                    <span>实名认证</span>
                </a>
              </li>
              <li>
                <a href="javascript:;" @click='logout'>
                    <i class='icon-quit'></i>
                    <span>退出</span>
                </a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
</template>

<script>
import { mapGetters } from 'vuex'
import store from '../../store'
export default {
  name: 'userList',
  data() {
    return {
      isUserListShow: false
    }
  },
  methods: {
     toogleUserList(flag) {
       this.isUserListShow = flag
     },
     logout() {
      store.dispatch('user/logout')
     },
     routerToUser(userid) {
       this.$router.push({path:'/user', query:{ id:userid}})
     }
  },
  computed: {
    ...mapGetters([
      'profile',
      'avatar',
      'userid'
    ])
  }
}
</script>

<style lang='less' scoped>
  .user-box {
   display: flex;
   justify-content: center;
   align-items: center;
   .user-name {
     color: #fff;
   }
   .user-img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    img {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background-color: skyblue;
    }
    &:hover .user-list-box {
      display: block;
    }
  }
  .user-list-h {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 10px solid #2e2c2c;
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
  }
  .user-list {
    position: absolute;
    z-index: 9999;
    width: 150px;
    height: 218px;
    background-color: #2e2c2c;
    top: 40px;
    left: -50px;
    ul {
      display: flex;
      flex-flow: column;
      flex-wrap: wrap;
      width: 100%;
      li {
        width: 100%;
        height: 30px;
        float: left;
        line-height: 30px;
        a {
          display: block;
          height: 100%;
          display: flex;
          align-items: center;
          font-size: 12px;
          padding-left: 35px;
          i {
            width: 20px;
            height: 20px;
            background: url('../../assets/toplist.png');
            margin-right: 15px;
          }
          span {
            height: 100%;
            line-height: 30px;
            color: #d5d5d5;
          }
          .icon-host {
            background-position: 3px 166px;
          }
          .icon-msg {
            background-position: -70px 371px;
          }
          .icon-lvl {
            background-position: -50px 390px;
          }
          .icon-vip {
            background-position: -50px 272px;
          }
          .icon-setting {
            background-position: -50px 351px;
          }
          .icon-real-name {
            background-position: -70px 349px;
          }
          .icon-quit {
            background-position: -50px 291px;
          }
          &:hover {
            background-color: #353535;
          }
        }
      }
    }
  }
 }
</style>